﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CapaEntidades;
using System.Data;
using System.Data.SqlClient;

namespace CapaDatos{
    public class datMarca{
        public static List<entMarca> ListarMarcas() {
            List<entMarca> Lista = null;
            SqlCommand cmd = null;
            SqlDataReader dr = null;
            try{
                Conexion cn = new Conexion();
                SqlConnection conex = cn.conectar();
                cmd = new SqlCommand("uspListarMarcas", conex);
                cmd.CommandType = CommandType.StoredProcedure;
                conex.Open();
                dr = cmd.ExecuteReader();
                Lista = new List<entMarca>();
                while(dr.Read()){
                    entMarca m = new entMarca();
                    m.idMarca = Convert.ToInt32(dr["idMarca"]);
                    m.Descripcion = dr["Descripcion"].ToString();
                    Lista.Add(m);
                }
            }catch (Exception e){
                Lista = null;
            }finally{
                cmd.Connection.Close();
            }
            return Lista;        }
    }
}
